package com.plane;

import javax.imageio.ImageIO;
import java.awt.*;
import java.io.IOException;
import java.util.ArrayList;

public class Anim {
    private int x;
    private int y;
    private int index;
    private int type;
    private static Image[] npcImgs;
    private static Image[] bulletImgs;

    static {
        try {
            npcImgs = new Image[]{
                    ImageIO.read(Npc.class.getResourceAsStream("bomb_enemy_0.png")),
                    ImageIO.read(Npc.class.getResourceAsStream("bomb_enemy_1.png")),
                    ImageIO.read(Npc.class.getResourceAsStream("bomb_enemy_2.png")),
                    ImageIO.read(Npc.class.getResourceAsStream("bomb_enemy_3.png")),
                    ImageIO.read(Npc.class.getResourceAsStream("bomb_enemy_4.png")),
                    ImageIO.read(Npc.class.getResourceAsStream("bomb_enemy_5.png")),
                    ImageIO.read(Npc.class.getResourceAsStream("bomb_enemy_6.png")),
            };
            bulletImgs = new Image[]{
                    ImageIO.read(Npc.class.getResourceAsStream("hited_0.png")),
                    ImageIO.read(Npc.class.getResourceAsStream("hited_1.png")),
                    ImageIO.read(Npc.class.getResourceAsStream("hited_2.png")),
                    ImageIO.read(Npc.class.getResourceAsStream("hited_3.png")),
                    ImageIO.read(Npc.class.getResourceAsStream("hited_4.png")),
            };
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public Anim(int type, int x, int y) {
        this.type = type;
        this.x = x;
        this.y = y;
    }

    public void paint(Graphics gTmp, GamePanel gp, ArrayList anims) {
        if (type == 0) {
            gTmp.drawImage(bulletImgs[index], x, y, gp);
            index++;
            if (index >= bulletImgs.length) {
                anims.remove(this);
            }
        } else {
            gTmp.drawImage(npcImgs[index], x, y, gp);
            index++;
            if (index >= npcImgs.length) {
                anims.remove(this);
            }
        }
    }
}
